﻿// See https://aka.ms/new-console-template for more information

using P3_StudentInfo;

int op = 100;
StudentManager studentManager = new StudentManager();

while (op != 0)
{
    Console.Clear();
    Console.WriteLine("学生信息管理系统");
    Console.WriteLine("1.查看所有学生信息");
    Console.WriteLine("2.查找学生");
    Console.WriteLine("3.增加学生信息");
    Console.WriteLine("4.删除学生信息");
    Console.WriteLine("0.退出系统");
    Console.WriteLine("请选择相应的功能:");
    string? input = Console.ReadLine();
    if (string.IsNullOrWhiteSpace(input))
    {
        Console.WriteLine("输入字符不能为空！");
        Console.ReadKey();
        continue;
    }
    if (!int.TryParse(input, out op))
    {
        Console.WriteLine("请输入正确的功能数字");
        continue;
    }

    string studentName = "";
    int studentAge = 0;
    double studentScore = 0;
    try
    {
        switch (op)
        {
            case 1:
                studentManager.PrintStudents();
                break;
            case 2:
                Console.WriteLine("请输入要查找的学生姓名：");
                studentName = Console.ReadLine();
                studentManager.FindStudent(studentName.Trim());
                break;
            case 3:
                Console.WriteLine("请输入要增加的学生姓名：");
                studentName = Console.ReadLine();
                Console.WriteLine("请输入要增加的学生的年龄：");
                studentAge = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("请输入要增加的学生分数：");
                studentScore = double.Parse(Console.ReadLine());
                studentManager.AddStudent(studentName.Trim(), studentAge, studentScore);
                break;
            case 4:
                Console.WriteLine("请输入要删除的学生姓名：");
                studentName = Console.ReadLine();
                studentManager.DeleteStudent(studentName.Trim());
                break;
            default:
                if (op!=0)
                {
                    Console.WriteLine("无效的输入，请重新输入");
                }
                break;
            
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("输入错误，请重新输入");
    }
    
    
    Console.WriteLine("按任意键继续...");
    Console.ReadKey();
}
